import React, { forwardRef } from 'react';
import { PullToRefresh as PullToRefreshClass } from 'antd-mobile-v2';

// export interface PullToRefreshProps {
//   direction?: 'up' | 'down';
//   distanceToRefresh?: number;
//   refreshing?: boolean;
//   onRefresh?: () => void;
//   indicator?: { activate?: JSX.Element; deactivate?: JSX.Element; release?: JSX.Element; finish?: JSX.Element };
//   damping?: number;
// }

const PullToRefresh: React.FC<any> = forwardRef((props, ref) => {
  const defaultProps = {
    direction: 'up',
    style: {
      height: document.documentElement.clientHeight, // 非全屏的滚动组件，需要单独计算传入固定高度
      overflow: 'auto'
    },
    indicator: {
      activate: <span>松开加载数据</span>,
      deactivate: <span>继续滑动加载数据</span>,
      finish: <span>加载完成</span>
    }
  };
  return (
    <PullToRefreshClass
      {...defaultProps}
      {...props}
      ref={ref}
    >
      {props.children}
    </PullToRefreshClass>
  );
});

export default PullToRefresh;